//
//  DeviceAPI.swift
//  casdon_swiftUI
//
//  Created by casdon on 2025/5/8.
//

import Foundation

enum DeviceAPI {
    // 配网页面，获取产品类型列表
    struct ApplianceTypeList: API {
        typealias Response = [Data]
        struct Data: Decodable {
            let id: String
            let code: String
            let name: String
            let nodeType: Int
            var parentId: String
            var remark: String?
            var deleted: String
        }
        
        let body: EmptyBody?
        let path: String = "/client-product/network/getApplianceTypeList"
        let method: HTTPMethod = .GET
        var headers: [String: String] = ["Content-Type": "application/json", "clientId": APP_CLIENTID, "Authorization": "Bearer " + (AuthManager.shared.getToken() ?? "")]
        let query: [String: String]? = nil
        let pathValues: [String: String]? = nil
        let requiresEncryption: Bool = false
        func withUpdatedHeaders(_ headers: [String: String]) -> Self {
            var copy = self
            copy.headers.merge(headers) { (current, _) in current }
            return copy
        }
    }
    
    // 配网页面，获取产品列表
    struct ProductListById: API {
        typealias Response = [Data]
        struct Data: Decodable {
            let id: String
            let applianceType: String
            let applianceTypeName: String
            let pid: String
            let name: String
            let model: String
            let imgUrl: String
            let imgUrlStr: String
            let devType: String
            let devTypeRemark: String
            let otherConfig: String
            let remark:String
            let status:String
            let delFlag: String
            let createTime: String
            let updateTime: String
            
        }
        
        let body: EmptyBody?
        let pathValues: [String: String]?
        let path: String = "/client-product/network/getProductListById/{id}"
        let method: HTTPMethod = .GET
        var headers: [String: String] = ["Content-Type": "application/json", "clientId": APP_CLIENTID, "Authorization": "Bearer " + (AuthManager.shared.getToken() ?? "")]
        let query: [String: String]? = nil
        let requiresEncryption: Bool = false
        func withUpdatedHeaders(_ headers: [String: String]) -> Self {
            var copy = self
            copy.headers.merge(headers) { (current, _) in current }
            return copy
        }
    }
    
    // 获取用户绑定的设备信息
    struct BindedDeviceInfo: API {
        typealias Response = [Data]
        struct Data: Decodable {
            let id: String
            let applianceType: String
            let applianceTypeName: String
            let pid: String
            let name: String
            let model: String
            let imgUrl: String
            let imgUrlStr: String
            let devType: String
            let devTypeRemark: String
            let otherConfig: String
            let remark:String
            let status:String
            let delFlag: String
            let createTime: String
            let updateTime: String
        }
        
        let body: EmptyBody?
        let pathValues: [String: String]?
        let path: String = "/client-user/user/device/{deviceId}"
        let method: HTTPMethod = .GET
        var headers: [String: String] = ["Content-Type": "application/json", "clientId": APP_CLIENTID, "Authorization": "Bearer " + (AuthManager.shared.getToken() ?? "")]
        let query: [String: String]? = nil
        let requiresEncryption: Bool = false
        func withUpdatedHeaders(_ headers: [String: String]) -> Self {
            var copy = self
            copy.headers.merge(headers) { (current, _) in current }
            return copy
        }
    }
    
    
    //GET
    // 获取用户绑定的设备信息
    struct BindedDeviceList: API {
        typealias Response = [Data]
        struct Data: Decodable {
            let id: String
            let applianceType: String
            let applianceTypeName: String
            let pid: String
            let name: String
            let model: String
            let imgUrl: String
            let imgUrlStr: String
            let devType: String
            let devTypeRemark: String
            let otherConfig: String
            let remark:String
            let status:String
            let delFlag: String
            let createTime: String
            let updateTime: String
        }
        
        let body: EmptyBody?
        let pathValues: [String: String]? = nil
        let path: String = "/client-user/user/device"
        let method: HTTPMethod = .GET
        var headers: [String: String] = ["Content-Type": "application/json", "clientId": APP_CLIENTID, "Authorization": "Bearer " + (AuthManager.shared.getToken() ?? "")]
        let query: [String: String]? = nil
        let requiresEncryption: Bool = false
        func withUpdatedHeaders(_ headers: [String: String]) -> Self {
            var copy = self
            copy.headers.merge(headers) { (current, _) in current }
            return copy
        }
    }
    
}
